/**
 * Created by fifths on 17-8-11.
 */
import {Injectable} from '@angular/core';
import {Headers, RequestOptions} from '@angular/http';
import {HttpService} from '../../../lib/service/http.service';
import {adSystemApiUrl} from '../../../../config/api';

@Injectable()
export class AttrMatchService {

  constructor(private httpService: HttpService) {

  }

  // 类目
  getCategoryList(level: number, parent: number, page = 1, pageSize = 9999) {
    const url = `${adSystemApiUrl}/v1/admin/goods_category/list?level=${level}&parent=${parent}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 三级绑定属性名
  getGoodsAttributeset(id: number, page = 1, pageSize = 9999) {
    const url = `${adSystemApiUrl}/v1/admin/goods_attribute_set/list?goods_category_id=${id}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取属性名
  getGoodsAttribute(goods_attribute_category_id: number, page = 1, pageSize = 9999) {
    const url = `${adSystemApiUrl}/v1/admin/goods_attribute/list?goods_attribute_category_id=${goods_attribute_category_id}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取属性值
  getGoodsAttributeValue(goods_attribute_id: number, page = 1, pageSize = 9999) {
    const url = `${adSystemApiUrl}/v1/admin/goods_attribute_value/list?goods_attribute_id=${goods_attribute_id}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 获取属性集值绑定
  getGoodsAttributeSetValue(goods_attribute_set_id: number, page = 1, pageSize = 9999) {
    const url = `${adSystemApiUrl}/v1/admin/goods_attribute_set_value/list?goods_attribute_set_id=${goods_attribute_set_id}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }


  // 绑定属性集和属性集值
  bindGoodsAttributeSetAndSetValue(data) {
    const url = `${adSystemApiUrl}/v1/admin/goods_attribute_set/bind`;
    const headers = new Headers({'Content-Type': 'application/json'});
    const options = new RequestOptions({headers: headers});
    const body = JSON.stringify({bindData: data});
    return this.httpService.httpPostAuth(url, body, options).map(rs => rs);
  }

  // 获取属性集绑定信息
  goodsAttributeSetFindByInfo(goods_category_id, goods_attribute_id) {
    const url = `${adSystemApiUrl}/v1/admin/goods_attribute_set/findByInfo?goods_category_id=${goods_category_id}&goods_attribute_id=${goods_attribute_id}`;
    return this.httpService.httpGetAuth(url).map(rs => rs);
  }

  // 删除属性集绑定
  goodsAttributeSetDel(id) {
    const url = `${adSystemApiUrl}/v1/admin/goods_attribute_set/` + id + '/del';
    return this.httpService.httpPostAuth(url, {}).map(rs => rs);
  }

}
